package com.iams.manage.instener;

import com.iams.common.utils.spring.SpringUtils;
import com.iams.manage.domain.Archive;
import com.iams.manage.domain.ArchiveFilingApproval;
import com.iams.manage.mapper.ArchiveFilingApprovalMapper;
import com.iams.manage.service.IArchiveService;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

public class ArchiveFilingEndListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution delegateExecution) {

        String businessKey = delegateExecution.getProcessInstanceBusinessKey();
        ArchiveFilingApprovalMapper archiveFilingApprovalMapper = SpringUtils.getBean(ArchiveFilingApprovalMapper.class);
        ArchiveFilingApproval archiveFilingApproval = archiveFilingApprovalMapper.selectArchiveFilingApprovalByBusinessKey(businessKey);

        IArchiveService archiveService = SpringUtils.getBean(IArchiveService.class);
        Archive archive = archiveService.selectArchiveById(archiveFilingApproval.getArchiveId());
        archive.setStatus("Archived");
        archiveService.updateArchive(archive);
    }
}
